//
//  ClockTableCell.m
//  test
//
//  Created by 朱圳 on 2018/2/3.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "ClockTableCell.h"
#import "UILabel+HgLabel.h"
@interface ClockTableCell()
@end
@implementation ClockTableCell


+ (instancetype)cellWithTableView:(UITableView *)tableView withReuseIdentifier:(NSString *)reuseIdentifier
{
    
    ClockTableCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    cell.selectionStyle = 0;
    if (cell == nil) {
        cell = [[ClockTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.contentView.backgroundColor = [UIColor clearColor];
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews{
    [self.contentView addSubview:self.classContentLabel];
    [self.classContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@10);
        make.bottom.equalTo(@-10);
        make.left.equalTo(@10);
        make.right.equalTo(@(-48));
    }];
    
    [self.contentView addSubview:self.clockBtn];
    [self.clockBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-12));
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.centerY.mas_equalTo(self);
        
    }];
    
    [self.contentView addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(@0);
        make.height.equalTo(@0.5);
    }];
}

-(UIButton *)clockBtn{
    if (!_clockBtn) {
        _clockBtn = [[UIButton alloc]init];
        [_clockBtn setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
        [_clockBtn addTarget:self action:@selector(allSelected:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _clockBtn;
}
- (UILabel *)classContentLabel{
    if (!_classContentLabel) {
        _classContentLabel = [[UILabel alloc]init];
        _classContentLabel.font = [UIFont systemFontOfSize:14];
        _classContentLabel.numberOfLines = 0;
    }
    return _classContentLabel;
}

-(UIView *)topView{
    if (!_topView) {
        _topView = [[UIView alloc]init];
        _topView.backgroundColor = [UIColor darkGrayColor];
    }
    return _topView;
}


-(void)allSelected:(UIButton *)sender{
    _contentModel.isChecked =!_contentModel.isChecked;
    if (_contentModel.isChecked) {
        [_clockBtn setImage:[UIImage imageNamed:@"stu-ka"] forState:UIControlStateNormal];
        NSLog(@"打卡");
        
    }else{
        [_clockBtn setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
        NSLog(@"取消打卡");
    }
    if (_relateDelegate) {
        if ([_relateDelegate respondsToSelector:@selector(clockAction:withModel:)]) {
            [_relateDelegate clockAction:sender withModel:_contentModel];
        }
    }
}
- (void)setContentModel:(ContentModel *)contentModel{
    _contentModel = contentModel;
    _classContentLabel.attributedText = [_classContentLabel getAttributedStringWithString:_contentModel.content lineSpace:2];
    
    if (_contentModel.isChecked) {
        [_clockBtn setImage:[UIImage imageNamed:@"stu-ka"] forState:UIControlStateNormal];
    }else{
        [_clockBtn setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}


@end

